package cn.kgc.student.controller;

import org.apache.commons.io.IOUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

@Controller
public class DownloadController {
    private Map<Integer, String> map = new HashMap();
    {
        map.put(1,"d:\\files\\P4270001.jpg");
        map.put(2,"d:\\files\\P4290016.jpg");
        map.put(3,"d:\\files\\P4290039.jpg");
        map.put(4,"d:\\files\\P4290073.jpg");
    }

//    @RequestMapping("/down.do")
//    public void down(Integer key, HttpServletRequest request, HttpServletResponse response) throws IOException {
//        if(!map.containsKey(key)){
//            response.setContentType("text/html;charset=utf-8");
//            response.getWriter().print("该文件编号不存在");
//            return;
//        }
//        File file = new File(map.get(key));
//        InputStream in = new FileInputStream(file);
//        response.setContentType("application/octet-stream");
//        response.addHeader("Content-Disposition","attachment;fileName="+file.getName());
//        IOUtils.copy(in, response.getOutputStream());
//    }

}
